//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(){
	var obj={"text":'新建贷款交易',"url":contextRootPath+'/tCMmCooperorgDeal/prepareExecute/toLoanDeal'};
	parent.showObj(obj);
}

//修改 事件
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待修改的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}
	var cooperorgCode = iframe.iframeObj["table"].getSelectedObjs("cooperorgCode");
	var contractCode = iframe.iframeObj["table"].getSelectedObjs("contractCode");
	var creditPackageName = iframe.iframeObj["table"].getSelectedObjs("creditPackageName");
	var dealCode = iframe.iframeObj["table"].getSelectedObjs("dealCode");
	var cooperativeAgencyDealStatus = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus");
	var obj={"text":'修改贷款交易',"url":contextRootPath+'/tCMmContract/prepareExecute/toBackLoanDetailUpdate?contractCode=' + contractCode + "&cooperorgCode=" + cooperorgCode + "&creditPackageName=" + creditPackageName + "&dealCode=" + dealCode + "&cooperativeAgencyDealStatus=" + cooperativeAgencyDealStatus+ "&idDeal=" + v_ids};
	parent.showObj(obj);
}

//修改 事件
function toUpdateDataOffer(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待修改的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}
	var contractCode = iframe.iframeObj["table"].getSelectedObjs("contractCode");
	var dealCode = iframe.iframeObj["table"].getSelectedObjs("dealCode");
	var obj={"text":'修改贷款放款',"url":contextRootPath+'/tCMmLoanDetail/prepareExecute/toBackLoanOfferUpdate?contractCode=' + contractCode + "&dealCode=" + dealCode + "&idDeal=" + v_ids};
	parent.showObj(obj);
}

// 拒绝放款：根据选择多个合作机构交易流水记录进行拒绝放款
function refusedDealLend(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	var dealStatus = iframe.iframeObj["table"].getSelectedObjs("cooperativeAgencyDealStatus").join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待拒绝放款的数据！");
		return;
	}
	//判断是否可以拒绝放款
	var complete = dealStatus.indexOf('02');//在途
	var complete1 = dealStatus.indexOf('01');//贷款状态：在途
	var complete2 = dealStatus.indexOf('03');//贷款状态：审批拒绝
	var complete3 = dealStatus.indexOf('04');//贷款状态：放款成功
	var complete4 = dealStatus.indexOf('05');//贷款状态：放款失败
	var complete5 = dealStatus.indexOf('06');//贷款状态：我司拒绝放款
	if(complete1>-1||complete2>-1||complete3>-1||complete4>-1||complete5>-1){
		alert("只有在途状态才能拒绝放款！");
		return;
	}
	var url = contextRootPath+"/cooperorgDeal/refusedLendByDealIds";
	var params = {"ids":v_ids};
	
	if(confirm("您确认要拒绝放款选择的数据吗？")){
		
		jyAjax(
				url,
				params,
				function(msg){
					//新增成功后，
					alert(msg.msg);
					var v_status = msg.status;
		        	if(v_status.indexOf('ok') >-1){
		        		//新增成功后 刷新页面 或 只查询 id为msg.data['id'] 的  数据
		        		queryData();
		        		alert("拒绝放款成功！");
		        	}
		  	});
    }
}

//删除 事件
function deleteData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/cooperorgDeal/deleteDeal?ids="+v_ids,
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframe.iframeObj["table"].removeSelectedRow();
            	}
            	
            	
            }
        });
    }
}

//移除数据
function removeData(){
	
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"?ids="+v_ids,
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframe.iframeObj["table"].removeSelectedRow();
            	}
            	
            	
            }
        });
    }
}

//修改 事件
function loanDealSettle(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待结算的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}
	var contractCode = iframe.iframeObj["table"].getSelectedObjs("contractCode");
	var dealCode = iframe.iframeObj["table"].getSelectedObjs("dealCode");
	
	if(confirm("请确认是否发送结算申请？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/cooperorgDeal/loandDealSettle?dealCode="+dealCode,
            success:function(msg){
            	alert(msg.msg);
            	queryData();
            }
        });
    }
}

//刷新结算状态
function refreshSettleStatus(){
	$.ajax({
		url: contextRootPath+"/creditDealController/realTimeUpdateSettleResult",
		type: 'post',
		dataType: 'json',
		success: function(msg) {
				jyDialog({"type":"info"}).alert(msg.msg);
				var v_status = msg.status;
		    	if(v_status.indexOf('ok') >-1){
		    		queryData();
		    	}
				
		}
	});
}
